﻿using System;
using YawetagLib.Data;

namespace YawetagLib.Services
{
    public sealed class DefaultServiceFactory : BaseServiceFactory
    {
        public DefaultServiceFactory(IDataContextFactory dataContextFactory)
        {
            DataContextFactory = dataContextFactory;
            DataManager = new DataManager(DataContextFactory);
        }

        protected override IService GetServiceInstance(Type serviceType)
        {
            return (IService)Activator.CreateInstance(serviceType, this, DataManager);
        }

        protected override void ManagedResourceCleanup()
        {
            base.ManagedResourceCleanup();

            DataContextFactory.Dispose();
        }

        private IDataContextFactory DataContextFactory { get; set; }

        private DataManager DataManager { get; set; }
    }
}
